﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TracNghiemTinHocDaiCuong.Common;
using TracNghiemTinHocDaiCuong.ThucThe;
using TracNghiemTinHocDaiCuong.BIZ;

namespace TracNghiemTinHocDaiCuong
{
    public partial class SuaChuDe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ChuDe chuDe = TimChuDe();
            if (!IsPostBack)
            {
                txtTenChuDe.Text = chuDe.TenCD;
                txtGhiChu.Text = chuDe.GhiChu;
            }
        }

        private ChuDe TimChuDe()
        {
            ViewState["idChuDe"] = Methods.ConvertNumber(Request.QueryString["ID"]);
            ChuDe chuDe = ChuDeBIZ.TimTheoId((int)ViewState["idChuDe"]);
            return chuDe;
        }

        protected void btnSua_Click(object sender, EventArgs e)
        {
            ChuDe chuDeSua = new ChuDe();
            ChuDe chuDeCu = TimChuDe();
            chuDeSua.MaCD = (int)ViewState["idChuDe"];
            chuDeSua.TenCD = txtTenChuDe.Text;
            chuDeSua.GhiChu = txtGhiChu.Text;
            ChuDeBIZ.Sua(chuDeSua);
            lblThongBao.Text = "Bạn đã sửa " + chuDeCu.TenCD + " thành công";
        }

        protected void btnXoaTuKhoa_Click(object sender, EventArgs e)
        {
            txtTenChuDe.Text = "";
            txtGhiChu.Text = "";
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyChuDe.aspx");
        }
    }
}